

alphabet = "abcdefghijklmnopqrstuvwxyz"




###############################################################
# Given a string s, returns the number of occurences of
# dictionary words (from wordlist.txt) in that string.
def wordCount(s):
    f = open('wordlist.txt')
    count = 0
    for i in range(60387):   # This range is specific to wordlist.txt
        word = f.readline().rstrip().lower()
        if word in s:
            count += 1
    return count
    
  
    
###############################################################
# Converts a character to a number based on its position in 
# the alphabet: a->0, b->1, c->2, d->3, etc.
def letter2number(c):
    return alphabet.index(c.lower())
    
###############################################################
# Converts a number to a character based on its position in 
# the alphabet: 0->a, 1->b, 2->c, 3->d, etc.
def number2letter(n):
    return alphabet[n%26]


###############################################################
# Frequency analysis
# Given a string S of characters, returns an array of letter 
# counts for a through z.  
def letterFrequency(S):
    frequency = []
    for c in range(26):
        count = 0
        for i in range(len(S)):
            if S[i] == alphabet[c]:
                count += 1 
        frequency.append(count)
    return frequency

###############################################################
# Frequency analysis
# Given a string S of characters, returns a list of unique 
# characters in descending order of the occurence in S. 
def characterFrequency(S):
    S = S.lower()
    characters = set(S)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
